package com.cloud.code.牛客网;

import java.util.*;

/**
 * HJ45 名字的漂亮度
 */
public class Test13 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());
        for (int i = 0; i < n; i++) {
            if(scanner.hasNext()){
                print(scanner.nextLine());
            }

        }
    }

    private static void print(String nextLine) {

        char[] chars = nextLine.toCharArray();
        Map<Character,Integer> map = new HashMap<>();
        for(Character character : chars){
            Integer integer = map.get(character);
            if(integer == null || integer.equals(0)){
                map.put(character,new Integer(1));
            }else {
                map.put(character,integer+1);
            }
        }

        List<Integer> list = new ArrayList<>();
        map.forEach((character, integer) -> {
            list.add(integer);
        });

        Collections.sort(list);

        int count = 0;
        int pl = 26;
        for (int i = list.size()-1; i >= 0; i--) {
            count = count+pl*list.get(i);
            pl --;
        }

        System.out.println(count);


    }
}
